﻿using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace DroidLord.app.dy
{
    class DYUserInfoData
    {
        public bool isParseOk = false;
        //头像
        public string avatar = "";
        //作品数
        public string awemeCount = "0";
        //total_favorited 获赞
        public string totalFavorited = "0";
        //
        public string uniqueId = "";
        public string nickName = "";
        public string signature = "";
        //粉丝数
        public string followerCount = "";
        //
        public string uid = "";
        public string shortId = "";
        //关注数
        public string followingCount = "";
        //喜欢的作品数
        public string favoritingCount = "0";

        private  string getValue(JObject userinfoobj, string key)
        {
            try
            {
                return userinfoobj[key].ToString();
            }
            catch (Exception eee)
            {
               // MessageBox.Show(eee.ToString());
            }
            return "";
        }
        public  DYUserInfoData  parseData(string userinfo)
        {
            //MessageBox.Show("" + userinfo);
            DYUserInfoData userInfo = new DYUserInfoData();
            string statusCode =JObject.Parse(userinfo)["status_code"].ToString();
            if(statusCode.Equals("0"))
            {
                userInfo.isParseOk = true;
                JObject userinfoobj = JObject.Parse(JObject.Parse(userinfo)["user_info"].ToString());
                userInfo.totalFavorited= getValue(userinfoobj, "total_favorited");
                userInfo.uniqueId = getValue(userinfoobj, "unique_id");
                userInfo.nickName = getValue(userinfoobj, "nickname");
                userInfo.signature = getValue(userinfoobj, "signature");
                userInfo.awemeCount = getValue(userinfoobj, "aweme_count");
                userInfo.followerCount = getValue(userinfoobj, "follower_count");
                userInfo.uid = getValue(userinfoobj, "uid");
                userInfo.shortId = getValue(userinfoobj, "short_id");
                userInfo.followingCount = getValue(userinfoobj, "following_count");
                userInfo.favoritingCount = getValue(userinfoobj, "favoriting_count");
                string avatar_medium = getValue(userinfoobj, "avatar_medium");
                string avatar_thumb = getValue(userinfoobj, "avatar_thumb");
                string avatar = "";
                if(!avatar_medium.Equals(""))
                {
                    avatar = avatar_medium;
                }
                else if (!avatar_thumb.Equals(""))
                {
                    avatar = avatar_thumb;
                }
                if(!avatar.Equals(""))
                {
                    JObject avatarObj = JObject.Parse(avatar);
                    string urlliststring = getValue(avatarObj, "url_list");
                    JArray myarray = JArray.Parse(urlliststring);
                    if(myarray.Count>0)
                    {
                        userInfo.avatar = myarray[0].ToString();
                    }
                }
            }

            return userInfo;
        }
    }
}
